//
//  LogCatAlertHelper.m
//  LogCat
//
//  Created by 清风徐来 on 2024/1/3.
//

#import "LogCatAlertHelper.h"
#import "LogCat/LogCatWindowHelper.h"

@implementation LogCatAlertHelper

/// 显示Alert弹窗
/// - Parameters:
///   - title: 标题
///   - message: 消息
///   - btnTitle: 按钮标题
+ (void)showAlertMessage:(NSString *)title message:(NSString *)message btnTitle:(NSString *)btnTitle {
    UIWindow *window = [LogCatWindowHelper.shared keyWindowForTransition:nil];
    [self showAlertMessage:title message:message btnTitle:btnTitle sender:[window rootViewController]];
}

/// 显示Alert弹窗
/// - Parameters:
///   - title: 标题
///   - message: 消息
///   - btnTitle: 按钮标题
///   - sender: 当前控制器
+ (void)showAlertMessage:(NSString *)title message:(NSString *)message btnTitle:(NSString *)btnTitle sender:(UIViewController * _Nullable)sender {
    [self showAlertMessage:title message:message btnTitle:btnTitle sender:sender handler:nil];
}

/// 显示Alert弹窗
/// - Parameters:
///   - title: 标题
///   - message: 消息
///   - btnTitle: 按钮标题
///   - sender: 当前控制器
///   - handler: 回调
+ (void)showAlertMessage:(NSString *)title message:(NSString *)message btnTitle:(NSString *)btnTitle sender:(UIViewController * _Nullable)sender handler:(void (^ __nullable)(UIAlertAction *action))handler {
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction *okAction = [UIAlertAction actionWithTitle:btnTitle style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        if (handler) {
            handler(action);
        }
    }];
    [alertController addAction:okAction];
    [sender presentViewController:alertController animated:YES completion:nil];
}


@end
